<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!--<script src="./js/page.js"></script>-->
    <title>S-Blog</title>
    <!-- Bootstrap -->
    <link href="css/bootstrap-4.3.1.css" rel="stylesheet">
  </head>
<body>
<script type="module" src="./js/marked.umd.js"></script>
<script>
  //paraName 等找参数的名称
  function GetUrlParam(paraName) {
    let url = document.location.toString();
    let arrObj = url.split("?");

    if (arrObj.length > 1) {
      let arrPara = arrObj[1].split("&");
      let arr;

      for (let i = 0; i < arrPara.length; i++) {
        arr = arrPara[i].split("=");

        if (arr != null && arr[0] === paraName) {
          return arr[1];
        }
      }
      return "";
    }
    else {
      return "";
    }
  }

  const getBlog = GetUrlParam("blog");
  const getpage = GetUrlParam("page");

  window.onload = function(){
    if(getBlog !== ''){
      console.log('blog name = '+getBlog);
      document.getElementById('pagetitle').innerText = decodeURIComponent(getBlog);
      $.get('http://127.0.0.1:9000/blog/get', { blogname : getBlog }, function(data, status){
        let newblog = document.createElement('P');
        //console.log(data);
        data = JSON.parse(data);
        newblog.textContent = data.blog;

        document.getElementById('page').innerHTML = marked.parse(data.blog);
        //document.getElementById('page').appendChild(newblog);
      })
    } else if(getpage !== ''){
      console.log('page name = '+getpage);
      document.getElementById('pagetitle').innerText = decodeURIComponent(getpage);
      $.get('http://127.0.0.1:9000/pages/get', { page : getpage }, function(data, status){
        let newpage = document.createElement('P');
        //console.log(data);
        data = JSON.parse(data);
        newpage.textContent = data.page;

        document.getElementById('page').innerHTML = marked.parse(data.page);
        //document.getElementById('page').appendChild(newpage);
      })
    }
  }
</script>
    <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
      <a class="navbar-brand" href="./">S-Blog&nbsp;</a>
      <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
      </button>
      <div class="collapse navbar-collapse" id="navbarSupportedContent">
        <ul class="navbar-nav mr-auto">
          <li class="nav-item">
            <a class="nav-link" href="./">主页 <span class="sr-only">(current)</span></a>
          </li>
          <li class="nav-item">
            <a class="nav-link" href="./page?page=projects">作品</a>
          </li>
          <li class="nav-item active">
            <a class="nav-link" href="./page?page=about">关于</a>
          </li>
        </ul>
        <form class="form-inline my-2 my-lg-0">
          <input class="form-control mr-sm-2" type="search" placeholder="搜索" aria-label="Search" id="searchtext">
          <button class="btn btn-outline-success my-2 my-sm-0" type="submit">搜索</button>
        </form>
      </div>
    </nav>
    <section>
      <div class="jumbotron text-center mt-2">
        <div class="container">
          <div class="row">
            <div class="col-12">
              <h1 id="pagetitle">pagetitle</h1>
              <p>醉后不知天在水，满船清梦压星河<br>基于开源博客系统S-Blog</p>
</div>
          </div>
        </div>
      </div>
    </section>
<br>
	<div class="container" id="page">
	</div>
<br>
<footer class="text-center">
  <div class="container">
        <div class="row">
          <div class="col-12">
            <p>Powered by <a href="https://github.com/SimpleAstronaut/S-Blog">S-Blog</a></p>
            <!--<p>Copyright © MyCompany. All rights reserved.</p>-->
          </div>
        </div>
      </div>
    </footer>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="js/jquery-3.3.1.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/popper.min.js"></script>
    <script src="js/bootstrap-4.3.1.js"></script>
  </body>
</html>